/**
  * This file is part of Medusa.
  *
  * Authors: Uriel Fanelli <uriel.fanelli@gmail.com>
  *          Perthect <perthect@gmail.com>
  *          Marco Bizzarri <Marco.Bizzarri@gmail.com>
  *
  *
  * Medusa is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.

  * Medusa is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.

  * You should have received a copy of the GNU General Public License
  * along with Medusa; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */

#include <QUrl>
#include <QMessageBox>

#include "tabzone.h"
#include "mainapp.h"
#include "singletab.h"
//class singleTab;

tabZone::tabZone(QWidget* parent)
    : QWidget(parent)
{
}

QTgoongress *tabZone::mainWindow()
{
}

//tabZone::tabZone(QNetworkAccessManager *manager)
tabZone::tabZone(QWidget* parent,QNetworkAccessManager *manager)
    : QWidget(parent)
{
//    this->manager = new QNetworkAccessManager;
    tmanager = manager;
//    this->parent = parent;
}

void tabZone::disegna(QUrl _url)
{
    mainLayout = new QGridLayout;
    midLayout = new QVBoxLayout;
//    this->manager = manager;
    iomichiamo(_url);
//    view = new singleTab(this);
    view = new singleTab(this,tmanager);
//    view = new singleTab(this->manager);
//    view->mostrapagina(_url); // WHATTA HELL IS WRONG WITH U? NOTHING BABY!
    view->load(_url);
//    view->show();
    progressBar = new GProgressBar;
    midLayout->addWidget(view);
    midLayout->addWidget(progressBar);
    mainLayout->addLayout(midLayout, 0, 0);
    setLayout(mainLayout);
    connect(view, SIGNAL(urlChanged(QUrl)), this->parent(), SLOT(aggiornatabtip(QUrl)));
    connect(view, SIGNAL(loadStarted()), progressBar, SLOT(pageLoadStarted()));
    connect(view, SIGNAL(loadStarted()), this, SLOT(pageLoadStarted()));
    connect(view, SIGNAL(loadProgress(int)), progressBar, SLOT(pageLoadInProgress(int)));
    connect(view, SIGNAL(loadFinished(bool)), progressBar, SLOT(pageLoadFinished(bool)));
    connect(view, SIGNAL(loadFinished(bool)), this, SLOT(pageLoadFinished(bool)));
}

tabZone::~tabZone()
{
//    delete this->view;
//    delete this->page;
}

void tabZone::pageLoadStarted()
{
    progressBar->show();
}

void tabZone::pageLoadFinished(bool result)
{
    progressBar->hide();
}

void tabZone::iomichiamo(QUrl url)
{
    michiamo = url;
}

QUrl tabZone::cometichiami()
{
    return michiamo;
}
